package com.itheima.service.mongo.impl;

import com.itheima.domain.mongo.FocusUser;
import com.itheima.service.mongo.FocusUserService;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;

/**
 * @author Guanxing
 * @date 2021/9/28
 */
@Service
public class FocusUserServiceImpl implements FocusUserService {

    @Autowired
    private MongoTemplate mongoTemplate;

    //关注
    @Override
    public void saveFocus(FocusUser focusUser) {
        focusUser.setCreated(System.currentTimeMillis());
        mongoTemplate.save(focusUser);
    }

    //取消关注
    @Override
    public void removeFocus(Long loginUserId, Long videoUserId) {
        Query query = new Query(
                Criteria.where("userId").is(loginUserId)
                        .and("focusUserId").is(videoUserId)
        );

        mongoTemplate.remove(query, FocusUser.class);
    }
}
